const fs = require("fs")
const {execute, joinRootDir}= require("../util.js")

module.exports = function (dirs= ["webindex"]) { //重新打包
    dirs.forEach(v=>{
      var dirBuild= joinRootDir("htmlProject/"+v+"/build")
      var dir= joinRootDir("htmlProject/"+v)
      fs.stat(dirBuild, function(err, stats) {
        if(err) return
        if(stats.isFile()) return

        console.log(v+'安装依赖')
        return execute("cnpm i",{cwd: dir}).catch(async rej=>{
          await execute("npm install -g cnpm --registry=https://registry.npm.taobao.org",{cwd: dir})
          return await execute("cnpm i",{cwd: dir})
        }).then(res=>{
          console.log(v+'安装依赖成功')
          console.log(v+'项目打包中')
          execute("npm run build",{cwd: dir}).then(()=>{console.log(v+'项目打包完成')})
        })
      })
    })
}